package jvm

import java.util.*

/**
 * @Author: DRevelation
 * @Date: 2021/9/23 17:16
 */
//class Person(parent: Person?) {
//    var children: MutableList<Person> = mutableListOf()
//
//    init {
//        parent?.children?.add(this)
//    }
//}

class Person(val name: String) {
    private val children: MutableList<Person> = mutableListOf()

    constructor(name: String, parent: Person) : this(name) {
        parent.children.add(this)
    }
}

open class Base(val name: String) {
    init {
        println("Initializing Base")
    }

    open val size: Int = name.length.also {
        println("Initializing size in Base: $it")
    }
}

class Derived(
    name: String,
    val last: String
) : Base(name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }.also { println("Argument for Base: $it") }) {
    init {
        println("Initializing Derived")
    }

    override val size:Int = (super.size + last.length).also {
        println("Initializing size in Derived: $it")
    }
}